package com.olda.play.system.service.impl;

import com.olda.play.enums.ResponseCode;
import com.olda.play.rpc.CommonResponseDto;
import com.olda.play.system.biz.SysUserBizService;
import com.olda.play.system.dto.SysUserDto;
import com.olda.play.system.service.SysUserService;
import com.olda.play.system.vo.SysUserVo;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 */
@Service
@RequestMapping(value =  "/user")
@RestController
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserBizService sysUserBizService;

    /**
     * 根据用户名获取用户信息
     * produces="application/json;charset=UTF-8"  //返回json格式
     * @param userName
     * @return
     */
    @RequestMapping(value = "/getUserDetailInfoByUserName",method = RequestMethod.POST ,produces="application/json;charset=UTF-8" )
    @Override
    public CommonResponseDto<SysUserDto> selectSysUserByUserName(@RequestParam(name = "userName" ,required = false) String userName) {
        //查询用户信息
        SysUserDto sysUserDto=sysUserBizService.selectSysUserByUserName(userName);
        return CommonResponseDto.success(sysUserDto);
    }

    /**
     * 分页获取用户列表
     * @return
     */
    @Override
    @RequestMapping(value = "/querySysUserList",method = RequestMethod.POST ,produces="application/json;charset=UTF-8" )
    public CommonResponseDto<List<SysUserDto>> querySysUserList(@RequestBody SysUserVo param) {
        return sysUserBizService.querySysUserList(param);
    }

    /**
     * 根据id查询用户最新详情
     * @param id
     * @return
     */
    @Override
    @RequestMapping(value = "/querySysUserDetailById",method = RequestMethod.GET ,produces="application/json;charset=UTF-8" )
    public CommonResponseDto<SysUserDto> querySysUserDetailById(Long id) {
        if(id==null){
            return CommonResponseDto.error(ResponseCode.ILLEGAL_ARGUMENT);
        }
        SysUserDto sysUserDto=sysUserBizService.selectSysUserById(id);
        return CommonResponseDto.success(sysUserDto);
    }
}
